package com.isunland.managesystem.ui;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CurrentUser;

public class CertificateChooseDialogFragment extends DialogFragment {
  protected static final int REQUEST_ADD_LOAN = 100;
  private int[] choiceIds = new int[] {
      R.string.employeeLoan_list, R.string.travelReimburse, R.string.manageReimburse,
      R.string.employeeRepay
  };
  private String[] choiceStrings = new String[choiceIds.length];
  private CurrentUser mUser;

  @Override public void onCreate(Bundle savedInstanceState) {
    mUser = CurrentUser.newInstance(getActivity());
    super.onCreate(savedInstanceState);
  }

  @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(getChoiceName(), 0,
        new OnClickListener() {

          @Override public void onClick(DialogInterface arg0, int arg1) {
            //点击dialog后跳转
            //员工借款支出详情参数
            StringBuilder code1 = new StringBuilder();
            code1.append(mUser.getMemberCode()).append("-").append("DJLB-CWZC-YGJKZC");

            //差旅费用报销详情参数
            StringBuilder code2 = new StringBuilder();
            code2.append(mUser.getMemberCode()).append("-").append("DJLB-CWZC-CLFYBX");

            //管理费用报销详情参数
            StringBuilder code3 = new StringBuilder();
            code3.append(mUser.getMemberCode()).append("-").append("DJLB-CWZC-GLFYBX");

            //员工还款页面
            StringBuilder code4 = new StringBuilder();
            code4.append(mUser.getMemberCode()).append("-").append("DJLB-CWSR-HKSR");
            Intent i = new Intent();
            switch (arg1) {
              case 0:
                //添加员工借款界面
                i = new Intent(getActivity(), AddEmpoyeeLoanActivity.class);
                i.putExtra(AddEmpoyeeLoanActivity.EXTRA_TYPE,
                    AddEmpoyeeLoanActivity.EXTRA_ADDCONTENTTYPE);
                i.putExtra(AddEmpoyeeLoanDetailFragment.EXTRA_CODE, code1.toString());
                break;
              case 1:
                //差旅报销界面（详情和明细）
                i = new Intent(getActivity(), TravelReimburseDetailActivity.class);
                i.putExtra(TravelReimburseDetailActivity.EXTRA_TYPE,
                    TravelReimburseDetailActivity.EXTRA_ADDCONTENTTYPE);
                i.putExtra(AddTravelReimburseDetailFragment.EXTRA_CODE, code2.toString());

                break;

              //管理费用报销界面
              case 2:
                //管理报销界面（详情和明细）
                i = new Intent(getActivity(), ManageReimburseDetailActivity.class);
                i.putExtra(ManageReimburseDetailActivity.EXTRA_TYPE,
                    ManageReimburseDetailActivity.EXTRA_ADDCONTENTTYPE);
                i.putExtra(AddManageReimburseDetailFragment.EXTRA_CODE, code3.toString());
                break;

              //员工还款界面
              case 3:
                i = new Intent(getActivity(), EmployeePaymentActivity.class);
                i.putExtra(EmployeePaymentActivity.EXTRA_TYPE,
                    EmployeePaymentActivity.EXTRA_ADDCONTENTTYPE);
                i.putExtra(AddEmployeePaymentFragment.EXTRA_CODE, code4.toString());
                break;

              default:
                break;
            }

            getActivity().startActivityForResult(i, REQUEST_ADD_LOAN);
            arg0.dismiss();
          }
        }).create();
  }

  private String[] getChoiceName() {
    for (int i = 0; i < choiceIds.length; i++) {

      choiceStrings[i] = getResources().getString(choiceIds[i]);
    }

    return choiceStrings;
  }
}
